package com.ruoyi.duanju.controller.my;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.duanju.domain.DjInputFile;
import com.ruoyi.duanju.service.my.MyDjService;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

@RequestMapping("/duanju/my")
@Controller
public class MyDjController extends BaseController {


    @Autowired
    MyDjService myDjService;

    @PreAuthorize("@ss.hasPermi('duanju:file:add')")
    @Log(title = "短剧导入文件", businessType = BusinessType.INSERT)
    @PostMapping("/addFile")
    public AjaxResult addFile(@RequestBody DjInputFile djInputFile)
    {
        try {
            return toAjax(myDjService.inputFile(djInputFile));
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

}
